package com.ag.lwc.action;

import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.apache.struts2.interceptor.SessionAware;
import com.ag.bean.TbUser;
import com.ag.bean.TbUserContact;
import com.ag.common.BaseAction;
import com.ag.common.IPermissionService;
import com.ag.lwc.service.UserContactService;

public class UserContactAction extends BaseAction implements SessionAware{
	/**
	 * 
	 */
	private static final long serialVersionUID = -4615874854013485527L;
	private String uid;							//当前用户id：
	private UserContactService userContactService;
	private TbUserContact currentUserContact;
	private String ucId;						//通信录id
	private List<TbUserContact> userContactList;
	private String message;
	
	@Resource(name = "PermissionServiceImpl")
	private IPermissionService pms;
	private Map<String, Object> sessionMap;
//查询所有通信录
	//try{}catch(Exception e){e.printStackTrace();}
	private String currentUserId()					//返回当前用户的id
	{
	///	uid =	(String) this.getSession().getAttribute("");
	
		uid = pms.getCurrentUser(sessionMap).getUId();			//获取当前用户的id
		System.out.println("当前用户的id："+uid);
//	uid="1000000001";
	return uid;
	}
	public String findAllContact()							//返回到通信录使用的界面
	{
		try{
			uid=this.currentUserId();
			userContactList = userContactService.findUseredContact(uid);
			System.out.println("当前用户id："+uid);
		}catch(Exception e){e.printStackTrace();}
		
		message = "find_AllContact";
		
		return "find_AllContact";
	}
	public String mainAllContact()						//返回到通信录的维护界面
	{
		try{
			uid=this.currentUserId();
			userContactList = userContactService.findUseredContact(uid);
			System.out.println("当前用户id："+uid);
		}catch(Exception e){e.printStackTrace();}
		
		message = "find_AllContact";
		
		return "main_AllContact";
	}
	public String findOneContact()
	{
		try{
			uid=this.currentUserId();
			System.out.println("用户某个通信录的id: "+this.ucId);
			currentUserContact = userContactService.findUseredContactById(ucId);
			message = "find_AllContact";
			
		}catch(Exception e){message="findError";e.printStackTrace();}
		return "find_OneContact";
	}
	public String add()
	{
		try{uid=this.currentUserId();
			TbUser user = new TbUser();
			user.setUId(uid);
			currentUserContact.setTbUser(user);
			System.out.println("UserContactAction: 增加的用户通信录： "+currentUserContact.getUcName());
			System.out.println("UserContactAction: 增加的用户通信录： "+currentUserContact.getUcName());
			message="add_UserContact";
		}catch(Exception e){e.printStackTrace();message="add_fail";}
		userContactService.add(currentUserContact);
	
		return "add_UserContact";
	}
	public String updateContact()
	{
		uid=this.currentUserId();
		TbUser user = new TbUser();
		user.setUId(uid);
		currentUserContact.setTbUser(user);
		System.out.println("通信录id："+currentUserContact.getUcId()+"	手机号码："+currentUserContact.getUcCellphone()+" 传真号码："+currentUserContact.getUcFax());
		userContactService.update(currentUserContact);
		message="update_UserContact";
		return "update_UserContact";
	}
	public String deleteContact()
	{
		
		userContactService.delete(ucId);
		message="delete_UserContact";
		return "delete_UserContact";
	}
	public UserContactService getUserContactService() {
		return userContactService;
	}
	public void setUserContactService(UserContactService userContactService) {
		this.userContactService = userContactService;
	}
	public TbUserContact getCurrentUserContact() {
		return currentUserContact;
	}
	public void setCurrentUserContact(TbUserContact currentUserContact) {
		this.currentUserContact = currentUserContact;
	}
	public String getUcId() {
		return ucId;
	}
	public void setUcId(String ucId) {
		this.ucId = ucId;
	}
	public List<TbUserContact> getUserContactList() {
		return userContactList;
	}
	public void setUserContactList(List<TbUserContact> userContactList) {
		this.userContactList = userContactList;
	}
	public String getMessage() {
		return message;
	}
	public void setMessage(String message) {
		this.message = message;
	}
	public String getUid() {
		return uid;
	}
	public void setUid(String uid) {
		this.uid = uid;
	}
	@Override
	public void setSession(Map<String, Object> arg0) {
		this.sessionMap=arg0;
		
	}
	public IPermissionService getPms() {
		return pms;
	}
	public void setPms(IPermissionService pms) {
		this.pms = pms;
	}
	

}
